<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="单据编号" prop="purchaseOrderNum">
        <el-input
          v-model="queryParams.purchaseOrderNum"
          clearable
          placeholder="请输入单据编号"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据日期" prop="docDate">
        <el-date-picker v-model="queryParams.docDate"
                        clearable
                        placeholder="请选择单据日期"
                        type="date"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="单据主题" prop="docSubject">
        <el-input
          v-model="queryParams.docSubject"
          clearable
          placeholder="请输入单据主题"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购员ID" prop="purchaserId">
        <el-input
          v-model="queryParams.purchaserId"
          clearable
          placeholder="请输入采购员ID"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务部门ID" prop="departmentId">
        <el-input
          v-model="queryParams.departmentId"
          clearable
          placeholder="请输入业务部门ID"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同编号" prop="contractNum">
        <el-input
          v-model="queryParams.contractNum"
          clearable
          placeholder="请输入合同编号"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商ID" prop="supplierId">
        <el-input
          v-model="queryParams.supplierId"
          clearable
          placeholder="请输入供应商ID"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contact">
        <el-input
          v-model="queryParams.contact"
          clearable
          placeholder="请输入联系人"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域" prop="area">
        <el-select v-model="queryParams.area" clearable placeholder="请选择区域">
          <el-option
            v-for="dict in dict.type.mes_area"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交货日期" prop="deliveryDate">
        <el-date-picker v-model="queryParams.deliveryDate"
                        clearable
                        placeholder="请选择交货日期"
                        type="date"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="单据阶段" prop="docStage">
        <el-input
          v-model="queryParams.docStage"
          clearable
          placeholder="请输入单据阶段"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据状态" prop="docState">
        <el-input
          v-model="queryParams.docState"
          clearable
          placeholder="请输入单据状态"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['purmgt:order:add']"
          icon="el-icon-plus"
          plain
          size="mini"
          type="primary"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['purmgt:order:edit']"
          :disabled="single"
          icon="el-icon-edit"
          plain
          size="mini"
          type="success"
          @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['purmgt:order:remove']"
          :disabled="multiple"
          icon="el-icon-delete"
          plain
          size="mini"
          type="danger"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['purmgt:order:export']"
          icon="el-icon-download"
          plain
          size="mini"
          type="warning"
          @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column align="center" fixed="left" type="selection" width="55"/>
      <el-table-column align="center" label="PK" prop="purchaseOrderId"/>
      <el-table-column align="center" label="单据编号" prop="purchaseOrderNum"/>
      <el-table-column align="center" label="单据日期" prop="docDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="单据主题" prop="docSubject"/>
      <el-table-column align="center" label="采购员ID" prop="purchaserId"/>
      <el-table-column align="center" label="业务部门ID" prop="departmentId"/>
      <el-table-column align="center" label="合同编号" prop="contractNum"/>
      <el-table-column align="center" label="供应商ID" prop="supplierId"/>
      <el-table-column align="center" label="联系人" prop="contact"/>
      <el-table-column align="center" label="联系电话" prop="phone"/>
      <el-table-column align="center" label="传真" prop="fax"/>
      <el-table-column align="center" label="手机" prop="mobile"/>
      <el-table-column align="center" label="地址" prop="address"/>
      <el-table-column align="center" label="E-mail" prop="email"/>
      <el-table-column align="center" label="区域" prop="area">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_area" :value="scope.row.area"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="交货日期" prop="deliveryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="交货地点" prop="deliveryPoint"/>
      <el-table-column align="center" label="运输方式" prop="transportModes"/>
      <el-table-column align="center" label="付款方式" prop="paymentMethod"/>
      <el-table-column align="center" label="结算方式" prop="settlementMethod"/>
      <el-table-column align="center" label="开票方式" prop="invoicingMethod"/>
      <el-table-column align="center" label="发票类型" prop="invoiceType"/>
      <el-table-column align="center" label="币种" prop="currency"/>
      <el-table-column align="center" label="汇率" prop="exchangeRate"/>
      <el-table-column align="center" label="合计采购数量" prop="sumPurchaseNum"/>
      <el-table-column align="center" label="合计采购金额" prop="sumTaxIncluded"/>
      <el-table-column align="center" label="单据阶段" prop="docStage"/>
      <el-table-column align="center" label="单据状态" prop="docState"/>
      <!--      <el-table-column label="附件" align="center" prop="attachmentFile" />-->
      <el-table-column align="center" label="备注" prop="remark"/>
      <el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作" width="150px">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['purmgt:order:edit']"
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            v-hasPermi="['purmgt:order:remove']"
            icon="el-icon-delete"
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改采购订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="90%" fullscreen>
      <el-form ref="form" :model="form" :rules="rules" :inline="true" label-width="110px">
        <el-form-item label="单据编号" prop="purchaseOrderNum">
          <el-input v-model="form.purchaseOrderNum" placeholder="请输入单据编号"/>
        </el-form-item>
        <el-form-item label="单据日期" prop="docDate">
          <el-date-picker v-model="form.docDate"
                          clearable
                          style="width: 200px;"
                          placeholder="请选择单据日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="单据主题" prop="docSubject">
          <el-input v-model="form.docSubject" placeholder="请输入单据主题"/>
        </el-form-item>
        <el-form-item label="采购员" prop="purchaserId">
          <el-select v-model="form.purchaserId" filterable clearable placeholder="请选择采购员" style="width:200px">
            <el-option
              v-for="dict in purchaserList"
              :key="dict.userName"
              :label="dict.nickName"
              :value="dict.userName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="业务部门" prop="departmentId">
          <el-input v-model="form.departmentId" placeholder="请输入业务部门"/>
        </el-form-item>
        <el-form-item label="合同编号" prop="contractNum">
          <el-input v-model="form.contractNum" placeholder="请输入合同编号"/>
        </el-form-item>
        <el-form-item label="供应商" prop="supplierId">
          <el-input v-model="form.supplierId" placeholder="请输入供应商"/>
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话"/>
        </el-form-item>
        <!--        <el-form-item label="传真" prop="fax">
                  <el-input v-model="form.fax" placeholder="请输入传真" />
                </el-form-item>
                <el-form-item label="手机" prop="mobile">
                  <el-input v-model="form.mobile" placeholder="请输入手机" />
                </el-form-item>
                <el-form-item label="地址" prop="address">
                  <el-input v-model="form.address" placeholder="请输入地址" />
                </el-form-item>
                <el-form-item label="E-mail" prop="email">
                  <el-input v-model="form.email" placeholder="请输入E-mail" />
                </el-form-item>
                <el-form-item label="区域" prop="area">
                  <el-select v-model="form.area" placeholder="请选择区域">
                    <el-option
                      v-for="dict in dict.type.mes_area"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>-->
        <el-form-item label="交货日期" prop="deliveryDate">
          <el-date-picker v-model="form.deliveryDate"
                          clearable
                          placeholder="请选择交货日期"
                          style="width: 200px;"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <!--        <el-form-item label="交货地点" prop="deliveryPoint">
                  <el-input v-model="form.deliveryPoint" placeholder="请输入交货地点" />
                </el-form-item>
                <el-form-item label="运输方式" prop="transportModes">
                  <el-input v-model="form.transportModes" placeholder="请输入运输方式" />
                </el-form-item>
                <el-form-item label="付款方式" prop="paymentMethod">
                  <el-input v-model="form.paymentMethod" placeholder="请输入付款方式" />
                </el-form-item>
                <el-form-item label="结算方式" prop="settlementMethod">
                  <el-input v-model="form.settlementMethod" placeholder="请输入结算方式" />
                </el-form-item>
                <el-form-item label="开票方式" prop="invoicingMethod">
                  <el-input v-model="form.invoicingMethod" placeholder="请输入开票方式" />
                </el-form-item>
                <el-form-item label="发票类型" prop="invoiceType">
                  <el-select v-model="form.invoiceType" placeholder="请选择发票类型">
                    <el-option label="请选择字典生成" value="" />
                  </el-select>
                </el-form-item>
                <el-form-item label="币种" prop="currency">
                  <el-input v-model="form.currency" placeholder="请输入币种" />
                </el-form-item>
                <el-form-item label="汇率" prop="exchangeRate">
                  <el-input v-model="form.exchangeRate" placeholder="请输入汇率" />
                </el-form-item>-->
        <el-form-item label="合计采购数量" prop="sumPurchaseNum">
          <el-input v-model="form.sumPurchaseNum" placeholder="请输入合计采购数量"/>
        </el-form-item>
        <el-form-item label="合计采购金额" prop="sumTaxIncluded">
          <el-input v-model="form.sumTaxIncluded" placeholder="请输入合计采购金额"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
        <el-form-item label="附件">
          <file-upload v-model="form.attachmentFile"/>
        </el-form-item>
        <el-divider content-position="center">{{
            activeName == '1' ? '采购订单明细信息' : '合同订单明细信息'
          }}
        </el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button icon="el-icon-plus" size="mini" type="primary" @click="handleAddPsiPurchaseOrderDetail">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handleDeletePsiPurchaseOrderDetail">
              删除
            </el-button>
          </el-col>
        </el-row>

        <el-tabs v-model="activeName">
          <el-tab-pane label="采购订单明细" name="1">
            <el-table ref="psiPurchaseOrderDetail" :data="psiPurchaseOrderDetailList"
                      :row-class-name="rowPsiPurchaseOrderDetailIndex"
                      @selection-change="handlePsiPurchaseOrderDetailSelectionChange">
              <el-table-column align="center" type="selection" width="50"/>
              <el-table-column align="center" label="序号" prop="index" width="50"/>
              <el-table-column label="物料ID" prop="materialId" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.materialId" placeholder="请输入物料ID"/>
                </template>
              </el-table-column>
              <el-table-column label="规格型号" prop="spec" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.spec" placeholder="请输入规格型号"/>
                </template>
              </el-table-column>
              <el-table-column label="库存单位" prop="sku" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.sku" placeholder="请输入库存单位"/>
                </template>
              </el-table-column>
              <el-table-column label="出库数量" prop="outboundQuantity" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.outboundQuantity" placeholder="请输入出库数量"/>
                </template>
              </el-table-column>
              <el-table-column label="销售单位" prop="salesUnit" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.salesUnit" placeholder="请输入销售单位"/>
                </template>
              </el-table-column>
              <el-table-column label="销售数量" prop="salesNum" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.salesNum" placeholder="请输入销售数量"/>
                </template>
              </el-table-column>
              <el-table-column label="税率%" prop="taxRate" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.taxRate" placeholder="请输入税率%"/>
                </template>
              </el-table-column>
              <el-table-column label="含税单价" prop="unitPrice" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.unitPrice" placeholder="请输入含税单价"/>
                </template>
              </el-table-column>
              <el-table-column label="折扣率%" prop="discountRate" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.discountRate" placeholder="请输入折扣率%"/>
                </template>
              </el-table-column>
              <el-table-column label="税额" prop="tax" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.tax" placeholder="请输入税额"/>
                </template>
              </el-table-column>
              <el-table-column label="含税金额" prop="taxIncluded" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.taxIncluded" placeholder="请输入含税金额"/>
                </template>
              </el-table-column>
              <el-table-column label="已入库数量" prop="inWh" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.inWh" placeholder="请输入已入库数量"/>
                </template>
              </el-table-column>
              <el-table-column label="未入库数量" prop="notInWh" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.notInWh" placeholder="请输入未入库数量"/>
                </template>
              </el-table-column>
              <el-table-column label="备注" prop="remark" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.remark" placeholder="请输入备注"/>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="合同订单明细" name="2">
            <el-table v-loading="loading" :data="contractList"
                      :row-class-name="rowPsiPurchaseOrderDetailIndex"
                      @selection-change="handleContractSelectionChange"
            >
              <el-table-column type="selection" width="55"/>
              <el-table-column label="税率(%)" prop="taxRate">
                <template slot-scope="scope">
                  <el-input-number  :step="0.01" style="width: 100%;"  :precision="2"  v-model="scope.row.taxRate"
                                    type="number"  maxlength="10"
                                    placeholder="请输入税率" />
                </template>
              </el-table-column>
              <el-table-column label="不含税金额" prop="excludingTax">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.excludingTax"
                            type="number"  maxlength="10"
                            placeholder="请输入不含税金额" />
                </template>
              </el-table-column>
              <el-table-column label="含税金额" prop="taxIncluded">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.taxIncluded"
                            type="number"  maxlength="10"
                            placeholder="请输入含税金额" />
                </template>
              </el-table-column>
              <el-table-column label="结算日期" prop="balanceDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.balanceDate"
                                  clearable
                                  style="width: 100%"
                                  placeholder="请选择结算日期"
                                  type="date"
                                  value-format="yyyy-MM-dd">
                  </el-date-picker>
                </template>
              </el-table-column>
              <el-table-column label="付款日期" prop="paymentDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.paymentDate"
                                  clearable
                                  style="width: 100%"
                                  placeholder="请选择付款日期"
                                  type="date"
                                  value-format="yyyy-MM-dd">
                  </el-date-picker>
                </template>
              </el-table-column>
              <el-table-column label="支付状态" prop="paymentStatu">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.paymentStatu"   placeholder="请选择支付状态" style="width:100%">
                    <el-option
                      v-for="dict in dict.type.mes_payment_statu"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="备注" prop="remark">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.remark" placeholder="请输入备注"/>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addOrder, delOrder, getOrder, listOrder, updateOrder} from "@/api/purmgt/order";
import {getAllUserList} from "@/api/system/user";

export default {
  name: "Order",
  dicts: [ 'mes_measurement_unit', 'mes_doc_state', 'mes_area', 'mes_invoicing_method', 'mes_invoice_type', 'mes_currency', 'mes_settlement_method', 'mes_payment_method', 'mes_transport' ,'mes_payment_statu'],
  data() {
    return {
      activeName:'1',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedPsiPurchaseOrderDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购订单表格数据
      orderList: [],
      // 采购订单明细表格数据
      psiPurchaseOrderDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        purchaseOrderNum: null,
        docDate: null,
        docSubject: null,
        purchaserId: null,
        departmentId: null,
        contractNum: null,
        supplierId: null,
        contact: null,
        phone: null,
        fax: null,
        mobile: null,
        address: null,
        email: null,
        area: null,
        deliveryDate: null,
        deliveryPoint: null,
        transportModes: null,
        paymentMethod: null,
        settlementMethod: null,
        invoicingMethod: null,
        invoiceType: null,
        currency: null,
        exchangeRate: null,
        sumPurchaseNum: null,
        sumTaxIncluded: null,
        docStage: null,
        docState: null,
        attachmentFile: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      contractList:[],
      purchaserList:[],
    };
  },
  created() {
    this.getList();
    this.getPurchaserList()
  },
  methods: {
    async getPurchaserList(){
      getAllUserList().then(res=>{

        this.purchaserList = res.data
      })
    },
    /** 查询采购订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.activeName = '1'
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        purchaseOrderId: null,
        purchaseOrderNum: null,
        docDate: null,
        docSubject: null,
        purchaserId: null,
        departmentId: null,
        contractNum: null,
        supplierId: null,
        contact: null,
        phone: null,
        fax: null,
        mobile: null,
        address: null,
        email: null,
        area: null,
        deliveryDate: null,
        deliveryPoint: null,
        transportModes: null,
        paymentMethod: null,
        settlementMethod: null,
        invoicingMethod: null,
        invoiceType: null,
        currency: null,
        exchangeRate: null,
        sumPurchaseNum: null,
        sumTaxIncluded: null,
        docStage: null,
        docState: null,
        delFlag: null,
        attachmentFile: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.psiPurchaseOrderDetailList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.purchaseOrderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 多选框选中数据
    handleContractSelectionChange(selection) {
      this.checkedPsiPurchaseOrderDetail = selection.map(item => item.index)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const purchaseOrderId = row.purchaseOrderId || this.ids
      getOrder(purchaseOrderId).then(response => {
        this.form = response.data;
        this.psiPurchaseOrderDetailList = response.data.psiPurchaseOrderDetailList;
        this.contractList = response.data.psiPurchaseContractList
        this.open = true;
        this.title = "修改采购订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.psiPurchaseOrderDetailList = this.psiPurchaseOrderDetailList;
          this.form.psiPurchaseContractList = this.contractList
          if (this.form.purchaseOrderId != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.getList();
              this.cancel()
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.getList();
              this.cancel()
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const purchaseOrderIds = row.purchaseOrderId || this.ids;
      this.$modal.confirm('是否确认删除采购订单编号为"' + purchaseOrderIds + '"的数据项？').then(function () {
        return delOrder(purchaseOrderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 采购订单明细序号 */
    rowPsiPurchaseOrderDetailIndex({row, rowIndex}) {
      row.index = rowIndex + 1;
    },
    /** 采购订单明细添加按钮操作 */
    handleAddPsiPurchaseOrderDetail() {
      let obj = {};
      if (this.activeName == '1') {
        obj.materialId = "";
        obj.spec = "";
        obj.sku = "";
        obj.outboundQuantity = "";
        obj.salesUnit = "";
        obj.salesNum = "";
        obj.taxRate = "";
        obj.unitPrice = "";
        obj.discountRate = "";
        obj.tax = "";
        obj.taxIncluded = "";
        obj.inWh = "";
        obj.notInWh = "";
        obj.remark = "";
        this.psiPurchaseOrderDetailList.push(obj);
      } else {
        obj.taxRate = ""
        obj.excludingTax = ""
        obj.taxIncluded = ""
        obj.balanceDate = ""
        obj.paymentDate = ""
        obj.paymentStatu = ""
        obj.remark = ""
        this.contractList.push(obj)
      }

    },
    /** 采购订单明细删除按钮操作 */
    handleDeletePsiPurchaseOrderDetail() {
      if (this.checkedPsiPurchaseOrderDetail.length == 0) {
        this.$modal.msgError("请先选择要删除的采购订单明细数据");
      } else {

        if(this.activeName === '1'){
          this.psiPurchaseOrderDetailList =  this.psiPurchaseOrderDetailList.filter( (item)=> {
            return  this.checkedPsiPurchaseOrderDetail.indexOf(item.index) == -1
          });
        }else {
          this.contractList = this.contractList.filter( (item)=> {
            return  this.checkedPsiPurchaseOrderDetail.indexOf(item.index) == -1
          });
        }
      }
    },
    /** 复选框选中数据 */
    handlePsiPurchaseOrderDetailSelectionChange(selection) {
      this.checkedPsiPurchaseOrderDetail = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('purmgt/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
